﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Pub;

public partial class upload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpPostedFile httpFile = Request.Files["FileData"];
        if (httpFile != null)
        {
            string fileName = httpFile.FileName;
            string preStr = "";
            //WebRequest req = WebRequest.Create(imgurlAry[i]);
            preStr = System.DateTime.Now.ToString("yyyyMMddHHmmss");
            string uploadPath = Server.MapPath("~") + "temp\\" + preStr + "_" + fileName;

            #region 保存文件名称到数据库
            string sUser = Session["user_id"] != null ? Session["user_id"].ToString() : "";
            string sFTyp = fileName.Length >= 3 ? fileName.Substring(fileName.Length - 3, 3) : "";
            string strSQL = "INSERT INTO wp_PEInfo (f_ID,FileName,Dat_S,FileType,u_ID) VALUES("
                + CDB.getNewID("wp_PEInfo", "f_ID") + ",'" + preStr + "_" + fileName + "','" 
                + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + sFTyp + "'," + sUser + ")";
            CADO ado1 = new CADO();
            ado1.cmd1(strSQL);
            CDebug.Send(strSQL);
            #endregion

            //string uploadPath = "D:\\temp\\" + fileName;
            httpFile.SaveAs(uploadPath);
            Session["filelist"] += uploadPath + "|";
            Response.Write("文件： " + uploadPath + " 上传成功！");
            Response.End();
        }
    }
}
